﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Intelligent.OTC.Common.UnitOfWork;
using Intelligent.OTC.Domain.DataModel;
using Intelligent.OTC.Domain.Repositories;
using System.Configuration;
using System.IO;
using Intelligent.OTC.Domain;
using Intelligent.OTC.Common;
using System.Data.Entity.Validation;
//using Intelligent.OTC.Common;
using Intelligent.OTC.Common.Attr;
using Intelligent.OTC.Common.Utils;
using Intelligent.OTC.Common.Exceptions;
using System.Data.Entity;
using System.Web;
using System.Text.RegularExpressions;
using Intelligent.OTC.Common.Repository;

namespace Intelligent.OTC.Business
{
    public class CustomerGroupCfgService
    {
        public OTCRepository CommonRep { get; set; }

        public CustomerGroupCfgService()
        { 
        }

        //public CustomerGroupCfg GetCurrentUser(string eid)
        //{
        //    return GetAllSites().Where(o => o.EID == eid).SingleOrDefault(); 
        //}

        public IQueryable<CustomerGroupCfg> GetAllGroups()
        {
            //return CommonRep.GetQueryable<CustomerGroupCfg>().Include<CustomerGroupCfg, ICollection<Customer>>(c => c.Custmer).AsQueryable();
            return CommonRep.GetQueryable<CustomerGroupCfg>().Where(o => o.Deal==AppContext.Current.User.Deal).AsQueryable();
        }
        public CustomerGroupCfg GetGroupByCode(string code) 
        {
           // return CommonRep.GetQueryable<CustomerGroupCfg>().Where(o => o.BillGroupCode == code);

            return CommonRep.GetQueryable<CustomerGroupCfg>().Where(o => o.BillGroupCode == code && o.Deal==AppContext.Current.User.Deal).FirstOrDefault();
        }
    }
}
